package com.ctshk.sapp.order.ship.controller;


import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.rpc.order.ship.dto.InsuranceReceiptDTO;
import com.ctshk.rpc.order.ship.dto.ShipOrderReceiptInfoDTO;
import com.ctshk.rpc.order.ship.req.ReceiptReq;
import com.ctshk.rpc.order.ship.req.ShipOrderReceiptReq;
import com.ctshk.rpc.order.ship.service.IShipOrderReceiptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import com.ctshk.common.web.support.BaseController;

import java.util.List;

/**
 * <p>
 * 船票订单收据 前端控制器
 * </p>
 *
 * @author 刘蕾
 * @since 2021-03-31
 */
@RestController
@RequestMapping("/ship-order-receipt")
@Api(value = "订单收据",tags = "订单收据")
public class ShipOrderReceiptController extends BaseController {

    @DubboReference
    IShipOrderReceiptService iShipOrderReceiptService;


    @ApiOperation(value = "收據详情", notes = "船票订单收據详情",tags = "订单收据")
    @OperationLogAnnotation(operModul = OperationLogModel.SHIP_ORDER, operType = OperationLogType.QUERY, operTitle = "船票订单收據详情", operDesc = "船票订单收據详情")
    @PostMapping(value="/info/receipt/{id}")
    public Result<ShipOrderReceiptInfoDTO> infoReceipt(@PathVariable Long id){
        return  iShipOrderReceiptService.info(id,getCurrentUser(getRequest()));
    }

    @ApiOperation(value = "編輯收據", notes = "編輯船票订单收據",tags = "订单收据")
    @OperationLogAnnotation(operModul = OperationLogModel.SHIP_ORDER, operType = OperationLogType.UPDATE, operTitle = "編輯船票订单收據", operDesc = "編輯船票订单收據")
    @PostMapping(value="/edit/receipt")
    public Result<ShipOrderReceiptInfoDTO> editReceipt(@RequestBody ShipOrderReceiptReq req){
        return  iShipOrderReceiptService.edit(req,getCurrentUser(getRequest()));
    }

    @ApiOperation(value = "保单收據详情", notes = "船票订单收據详情",tags = "订单收据")
    @OperationLogAnnotation(operModul = OperationLogModel.SHIP_ORDER, operType = OperationLogType.QUERY, operTitle = "船票订单收據详情", operDesc = "船票订单收據详情")
    @PostMapping(value="/insurance/receipt/{id}")
    public Result<List<InsuranceReceiptDTO>> insuranceReceipt(@PathVariable Long id){
        return  iShipOrderReceiptService.insuranceReceipt(id,getCurrentUser(getRequest()));
    }

    @ApiOperation("下载收据")
    @OperationLogAnnotation(operModul = OperationLogModel.SHIP_ORDER, operType = OperationLogType.OTHER, operTitle = "下载保单收据", operDesc = "下载保单收据")
    @PostMapping("downloadReceipt")
    public ResponseEntity<byte[]> downloadReceipt(@RequestBody ReceiptReq receiptReq) {
        byte[] body = "123".getBytes();
        HttpHeaders headers = new HttpHeaders();
        headers.add("Content-Disposition", "attchement;filename=" + "123.pdf");
        HttpStatus statusCode = HttpStatus.OK;
        ResponseEntity<byte[]> entity = new ResponseEntity<byte[]>(body, headers, statusCode);
        return entity;
    }

    @ApiOperation("收据发送邮件")
    @OperationLogAnnotation(operModul = OperationLogModel.SHIP_ORDER, operType = OperationLogType.OTHER, operTitle = "保单收据发送邮件", operDesc = "保单收据发送邮件")
    @GetMapping("sendEmailReceipt")
    public Result<Void> sendEmailReceipt(@RequestBody ReceiptReq receiptReq) {
        return new Result<>();
    }

    @ApiOperation("下载保单收据")
    @OperationLogAnnotation(operModul = OperationLogModel.SHIP_ORDER, operType = OperationLogType.OTHER, operTitle = "下载保单收据", operDesc = "下载保单收据")
    @PostMapping("insurance-download")
    public ResponseEntity<byte[]> downloadReceipt2(@RequestBody ReceiptReq receiptReq) {
        byte[] body = "123".getBytes();
        HttpHeaders headers = new HttpHeaders();
        headers.add("Content-Disposition", "attchement;filename=" + "123.pdf");
        HttpStatus statusCode = HttpStatus.OK;
        ResponseEntity<byte[]> entity = new ResponseEntity<byte[]>(body, headers, statusCode);
        return entity;
    }

    @ApiOperation("保单收据发送邮件")
    @OperationLogAnnotation(operModul = OperationLogModel.SHIP_ORDER, operType = OperationLogType.OTHER, operTitle = "保单收据发送邮件", operDesc = "保单收据发送邮件")
    @GetMapping("insurance-email")
    public Result<Void> sendEmailReceipt2(@RequestBody ReceiptReq receiptReq) {
        return new Result<>();
    }
}
